// pages/newhome/newhome.js
const api = require("../request/api")
const request = require("../request/request")
const util = require("../utils/util")
const App = getApp();

Page({
    /**
     * 页面的初始数据
     */
    data: {
        uid: 9,
        page: 1,
        page_size: 15,
        shop_list: [],
        good_list: [],
        point_list: [],
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
      this.get_good_list(0)
        this.setData({
          uid: util.getAppValue(App.globalData.uid),
        })
      this.get_shop_list()
    },
    get_good_list(type) {
      let params = {
        uid: this.data.uid,
        page: this.data.page,
        pageSize: this.data.page_size,
        type,
      }
      request.post(api.goods_list, params).then(res=>{
        this.setData({
          good_list: res
        })
      })
    },
    get_point_list() {
      let params = {
        uid: this.data.uid,
        page: this.data.page,
        pageSize: this.data.page_size,
        type: this.data.type,
        goods_type: "costpoint"
      }
      util.showLoading('加载中')
      request.post(api.goods_list, params).then(res => {
        util.hideLoading()
        this.setData({
          point_list: res,
        })
      })
    },
    go_search() {
        wx.navigateTo({
            url: '/pages/good/search',
        })
    },

    go_shop(event) {
      let id = event.currentTarget.dataset.id
        let url = '/pages/shop/shop?category=' + id
        wx.navigateTo({
            url
        })
    },

    go_groupbuy() {
        wx.navigateTo({
            url: '/plugins-groupbuy/plugins-groupbuy',
        })
    },

    go_locallife() {
        wx.navigateTo({
            url: "/plugins-locallife/plugins-locallife"
        })
    },

    go_ticket() {
        wx.navigateTo({
            url: "/plugins-ticket/plugins-ticket"
        })
    },

    go_hotel() {
        wx.navigateTo({
            url: "/plugins-hotel/plugins-hotel"
        })
    },

    go_movie() {
        wx.navigateTo({
            url:"/plugins-movie/plugins-movie"
        })
    },

    go_settling() {
        wx.navigateTo({
            url: '/pages/shop/settling',
        })
    },

    go_onlineshop() {
        wx.switchTab({
            url: "/pages/onlineshop"
        })
    },

    go_signin() {
        wx.navigateTo({
            url: "/pages/signin/signin",
        })
    },

    go_getticket() {
        wx.navigateTo({
            url: "/pages/ticket/newticket",
        })
    },
    go_settling() {
        wx.navigateTo({
            url: '/pages/shop/settling',
        })
    },
    go_shop_detail(e) {
      let id = e.currentTarget.dataset.id
      if (!id) {
        id = 32
      }
      wx.navigateTo({
        url: '/pages/shop/detail?id=' + id,
      })
    },
    get_shop_list() {
        let params = {
            page: this.data.page,
            limit: 3,
            uid: this.data.uid
        }
        request.post(api.shoplist, params).then(res => {
          console.log(res)
            this.setData({
                shop_list: res
            })
        })
    },

    go_shop_detail(e) {
        let id = e.currentTarget.dataset.id
        
        wx.navigateTo({
            url: '/pages/shop/detail?id=' + id,
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})